<template>
    <div>
        <h3>测试专用---登录界面</h3>
        <div >
          <el-card>
            用户名：
            <el-input placeholder="请输入用户名" v-model="username" ></el-input>
            密  码：
            <el-input placeholder="请输入密码" v-model="password" show-password></el-input>
          </el-card>
          <el-card>
            <el-button type="primary" @click="login">登录</el-button>
            <el-button type="primary" @click="">注册</el-button>
          </el-card>
        </div>
    </div>
</template>

<script>
    export default {
      name: "WelCome",

      data() {
        return {

          growthValue1:0,
          username:'',
          password:'',
          user:{

          },
          addValueForm:{
            uid:0,
            username:'',
            growthValue:0,
            beiZhu:'登录'
          }


        }

      },

      methods:{
        login() {
          let url = "course/denglu";
          this.$axios.get(url, {
            params: {
              username:this.username,
              password1:this.password,
            }
          }).then(res => {
            if (res.data.code == 200) {
              this.$message({
                type: "success",
                message: res.data.msg,
                duration: 1000
              })
              this.user=res.data.data;
              this.getGrowth();
              this.addGrowth();
              this.setSeesion();
            } else {
              this.$message({
                type: "error",
                message: res.data.msg,
                duration: 1000
              })
            }
          });
        },



        //获得登录相对的成长值
        getGrowth(){
          let url = "course/getLoginGet";
          this.$axios.get(url).then(res => {
            if (res.data.code == 200) {
              this.$message({
                type: "success",
                message: res.data.msg,
                duration: 1000
              })
              this.growthValue1=res.data.data;
              console.log(res.data)

            } else {
              this.$message({
                type: "error",
                message: res.data.msg,
                duration: 1000
              })
            }
          });
        },

        //登录增加成长值
        addGrowth(){
          this.addValueForm.uid=this.user.id
          this.addValueForm.username=this.user.username
          this.addValueForm.growthValue=this.growthValue1
          let url = "course/addLogValue";
          this.$axios.post(url,this.addValueForm).then(res=>{
            if (res.data.code == 200){
              console.log(res)
              this.pageNum = res.data.data.pageNum;
              this.pageSize = res.data.data.pageSize;
              this.total = res.data.data.total;
            }else {
              this.$message({
                type:"error",
                message:res.data.msg,
                duration:1000
              })
            }
          });
        },

        setSeesion(){
          sessionStorage.setItem("user", JSON.stringify(this.user));
          this.$router.push("/Page1")
        },
      },

      created() {

      }
    }
</script>

<style scoped>

</style>